package com.xry.service.impl;

import com.xry.annotation.LogMethod;
import com.xry.bean.Role;
import com.xry.mapper.RoleDao;
import com.xry.service.RoleService;
import com.xry.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleDao roleDao;
    @Override
    @LogMethod(serviceName = "增加角色信息")
    public Role add(Role role) {
        //新增数据
        roleDao.add(role);
        //通过主键查询数据库中的数据
        Role result = roleDao.one(role.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "修改角色信息")
    public int del(Integer id) {
        return roleDao.del(id);
    }


    @Override
    @LogMethod(serviceName = "修改角色信息")
    public Role edit(Role role) {
        roleDao.edit(role);
        Role result=roleDao.one(role.getId());
        return result;
    }

    @Override
    public List<Role> all(Role role) {
        return roleDao.all( role);
    }

    @Override
    public Role one(Integer id) {
        return roleDao.one(id);
    }

    @Override
    public void page(Page page, Role role){
        int count=roleDao.pageCount(role);
        Object data=roleDao.page(page,role);
        page.setCount(count);
        page.setData(data);
    }
}
